//
//  JKGJCell.m
//  Tunnel
//
//  Created by wbb on 2025/6/14.
//

#import "YJXYCell.h"
@interface YJXYCell ()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *detailLabel;

@property (nonatomic, strong) UILabel *typeLabel;
@property (nonatomic, strong) UILabel * ssxtLab;
@property (nonatomic, strong) UILabel * sbfxLab;
@property (nonatomic, strong) UILabel * sbzhLab;

@property (nonatomic, strong) UILabel  *gradeLabel;

@end
@implementation YJXYCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.backgroundColor = [UIColor clearColor];
        
        self.contentView.backgroundColor = [UIColor clearColor];
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:bgView];
    bgView.layer.shadowColor = [UIColor colorWithRed:156/255.0 green:175/255.0 blue:210/255.0 alpha:0.2].CGColor;
    bgView.layer.shadowOffset = CGSizeMake(0,4);
    bgView.layer.shadowOpacity = 1;
    bgView.layer.shadowRadius = 8;
    bgView.layer.cornerRadius = 7;
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.bottom.offset(-15);
        make.left.offset(12);
        make.right.offset(-12);
    }];
    
    
    // 创建标题标签
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.font = [UIFont systemFontOfSize:17];
    self.titleLabel.textColor = main_text_color;
    self.titleLabel.text = @"液位浮球 - YWJ-01";
    [bgView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(16);
        make.top.offset(12);
    }];
    
    UIStackView *typeStackView = [[UIStackView alloc] init];
    typeStackView.spacing = 8;
    [bgView addSubview:typeStackView];
    
    self.typeLabel = [[UILabel alloc] init];
    self.typeLabel.font = [UIFont systemFontOfSize:14];
    self.typeLabel.numberOfLines = 0;
    self.typeLabel.text = @"处置中";
    self.typeLabel.textAlignment = NSTextAlignmentCenter;
    self.typeLabel.textColor = hexColor(318C2D);
    self.typeLabel.backgroundColor = hexColor(EEFFEB);
    //    [bgView addSubview:self.typeLabel];
    //    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.centerY.mas_equalTo(self.titleLabel.mas_centerY).offset(0);
    //        make.right.offset(-8);
    //        make.width.offset(64);
    //        make.height.offset(22);
    //    }];
    
    
    self.gradeLabel = [[UILabel alloc] init];
    self.gradeLabel.font = [UIFont systemFontOfSize:14];
    self.gradeLabel.numberOfLines = 0;
    self.gradeLabel.text = @"二级";
    self.gradeLabel.textAlignment = NSTextAlignmentCenter;
    self.gradeLabel.textColor = hexColor(318C2D);
    self.gradeLabel.backgroundColor = hexColor(EEFFEB);

    [typeStackView addArrangedSubview:self.gradeLabel];
    [typeStackView addArrangedSubview:self.typeLabel];
    
    [self.gradeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(64);
        make.height.offset(22);
    }];
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(64);
        make.height.offset(22);
    }];
    [typeStackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.titleLabel.mas_centerY).offset(0);
        make.right.offset(-8);
    }];
    
    
    UIStackView *stackView1 = [[UIStackView alloc] init];
    stackView1.spacing = 10;
    [bgView addSubview:stackView1];
    [stackView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(5);
        make.height.offset(20);
    }];
    
    UILabel *leftLab1 = [[UILabel alloc] init];
    leftLab1.text = @"事件类型";
    leftLab1.textColor = main_light_text_color_9;
    leftLab1.font = [UIFont systemFontOfSize:14];
    
    self.ssxtLab = [[UILabel alloc] init];
    self.ssxtLab.text = @"所属系统";
    self.ssxtLab.textColor = main_light_text_color_6;
    self.ssxtLab.font = [UIFont systemFontOfSize:14];
    
    [stackView1 addArrangedSubview:leftLab1];
    [stackView1 addArrangedSubview:self.ssxtLab];
    
    UIStackView *stackView2 = [[UIStackView alloc] init];
    stackView2.spacing = 10;
    [bgView addSubview:stackView2];
    [stackView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.equalTo(stackView1.mas_bottom);
        make.height.offset(20);
    }];
    
    UILabel *leftLab2 = [[UILabel alloc] init];
    leftLab2.text = @"涉及车道";
    leftLab2.textColor = main_light_text_color_9;
    leftLab2.font = [UIFont systemFontOfSize:14];
    
    self.sbfxLab = [[UILabel alloc] init];
    self.sbfxLab.text = @"所属系统";
    self.sbfxLab.textColor = main_light_text_color_6;
    self.sbfxLab.font = [UIFont systemFontOfSize:14];
    
    [stackView2 addArrangedSubview:leftLab2];
    [stackView2 addArrangedSubview:self.sbfxLab];
    
    
    UIStackView *stackView3 = [[UIStackView alloc] init];
    stackView3.spacing = 10;
    [bgView addSubview:stackView3];
    [stackView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.equalTo(stackView2.mas_bottom);
        make.height.offset(20);
    }];
    
    
    
    UILabel *leftLab3 = [[UILabel alloc] init];
    leftLab3.text = @"发生事件";
    leftLab3.textColor = main_light_text_color_9;
    leftLab3.font = [UIFont systemFontOfSize:14];
    
    self.sbzhLab = [[UILabel alloc] init];
    self.sbzhLab.text = @"所属系统";
    self.sbzhLab.textColor = main_light_text_color_6;
    self.sbzhLab.font = [UIFont systemFontOfSize:14];
    
    [stackView3 addArrangedSubview:leftLab3];
    [stackView3 addArrangedSubview:self.sbzhLab];
    
    
    UILabel *lineLab = [UILabel new];
    lineLab.backgroundColor = main_line_color;
    [bgView addSubview:lineLab];
    [lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.mas_equalTo(stackView3.mas_bottom).offset(5);
        make.height.offset(1);
    }];
    
    self.detailLabel = [[UILabel alloc] init];
    self.detailLabel.font = [UIFont systemFontOfSize:14];
    self.detailLabel.textColor = main_text_color;
    self.detailLabel.text = @"查看详情";
    [bgView addSubview:self.detailLabel];
    [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.equalTo(lineLab.mas_bottom).offset(10);
    }];
    
    
    UIImageView *arrowImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right_arrow"]];
    [bgView addSubview:arrowImg];
    [arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-8);
        make.centerY.equalTo(self.detailLabel.mas_centerY).offset(0);
        make.height.width.offset(22);
    }];
    
    
    
    
    
}

- (void)goDetail {
    if(self.goDetailBlock) {
        self.goDetailBlock();
    }
}
- (void)setCornerForIndexPath:(NSIndexPath *)indexPath totalRows:(NSInteger)totalRows dataSource:(NSArray *)dataArray {
    
    NSDictionary *dic = dataArray[indexPath.row];
    
    self.imgView.image = [UIImage imageNamed:dic[@"imgName"]];
    self.titleLabel.text = dic[@"title"];
}

- (void)setModel:(YJXYModel *)model{
    self.gradeLabel.textColor = hexColor(CC4CD4);
    self.gradeLabel.backgroundColor = hexColorAlpha(CC4CD4,0.1);
    if([model.sjdj isEqualToString:@"II"]) {
        self.gradeLabel.textColor = hexColor(E7953D);
        self.gradeLabel.backgroundColor = hexColor(FFF6EB);
    }else if([model.sjdj isEqualToString:@"I"]) {
        self.gradeLabel.textColor = hexColor(FF5454);
        self.gradeLabel.backgroundColor = hexColor(FFEBEB);
    }else if([model.sjdj isEqualToString:@"III"]) {
        self.gradeLabel.textColor = hexColor(CDCF13);
        self.gradeLabel.backgroundColor = hexColor(FEFFEB);
    }
    self.typeLabel.text = @"误报";
    self.typeLabel.textColor = hexColor(FF5454);
    self.typeLabel.backgroundColor = hexColorAlpha(FF5454, 0.1);
    if([model.sjzt isEqualToString:@"DONE"]){
        self.typeLabel.text = @"已处置";
        self.typeLabel.textColor = hexColor(318C2D);
        self.typeLabel.backgroundColor = hexColor(EEFFEB);
    }else if ([model.sjzt isEqualToString:@"DOING"]){
        self.typeLabel.text = @"处置中";
        self.typeLabel.textColor = hexColor(5490FF);
        self.typeLabel.backgroundColor = hexColor(EBF2FF);
    }else if ([model.sjzt isEqualToString:@"INIT"]){
        self.typeLabel.text = @"待确认";
        self.typeLabel.textColor = hexColor(F3A642);
        self.typeLabel.backgroundColor = hexColorAlpha(F3A642, 0.1);
    }
    self.gradeLabel.text = model.sjdj.length!=0?[NSString stringWithFormat:@"%@级",model.sjdj]:@"-";
    self.titleLabel.text = [NSString stringWithFormat:@"%@ %@",model.direction,model.pileNo];
    self.sbfxLab.text =  model.laneno;
    self.sbzhLab.text = model.createTime;
    for (NSDictionary * dict in _typeArr) {
        if([dict[@"dictValue"] isEqualToString:model.sjlx]){
            self.ssxtLab.text = dict[@"dictLabel"];
            break;
        }
    }
    
    
}
@end
